package com.helen.ui.recoveryorder;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.helen.entity.RecoveryDetailEntity;
import com.helen.global.Constants;
import com.helen.shopping.R;
import com.helen.ui.BaseActivity;
import com.helen.utils.JsonUtil;
import com.helen.utils.MyLog;
import com.helen.utils.tiputils.MToast;
import com.zhouyou.http.EasyHttp;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.HttpParams;

import butterknife.BindView;

/**
 * Created by yang on 2018/7/5.
 */

public class RecoveryOrderDetailActivity extends BaseActivity {
    @BindView(R.id.tv_recovery_order_status)
    TextView tvRecoveryOrderStatus;
    @BindView(R.id.img)
    ImageView img;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_detail_address)
    TextView tvDetailAddress;
    @BindView(R.id.img_address_right)
    ImageView imgAddressRight;
    @BindView(R.id.ll_address)
    LinearLayout llAddress;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.tv_good_name)
    TextView tvGoodName;
    @BindView(R.id.tv_weight)
    TextView tvWeight;
    @BindView(R.id.tv_quality)
    TextView tvQuality;
    @BindView(R.id.view_line)
    View viewLine;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_note)
    TextView tvNote;
    @BindView(R.id.tv_dismissal)
    TextView tvDismissal;
    private String sid;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_recovery_detail;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        imgAddressRight.setVisibility(View.GONE);
        sid = getIntent().getStringExtra("id");
        recoveryDetailApi();
    }

    @Override
    protected void updateViews() {

    }


    private void recoveryDetailApi() {
        mMProgressDialog.show();
        HttpParams params = new HttpParams();
        params.put("sid", sid);
        EasyHttp.post(Constants.API_JSONAPI_RECOVERYDETAIL)
                .params(params)
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                        mMProgressDialog.dismiss();
                    }

                    @Override
                    public void onError(ApiException e) {

                    }

                    @Override
                    public void onSuccess(String result) {
                        MyLog.e("yang", "回收详情==" + result);
                        int code = JsonUtil.getJsonValuesInt(result, "code");
                        String msg = JsonUtil.getJsonValuesString(result, "msg");
                        if (code == 0) {
                            Gson gson = new GsonBuilder().create();
                            RecoveryDetailEntity recoveryDetailEntity = gson.fromJson(result, RecoveryDetailEntity.class);
                            String type = recoveryDetailEntity.getType();
                            getToolbarTitle().setText(type+"详情");
                            int status = recoveryDetailEntity.getState();
                            switch (status){
                                case 1:
                                    tvRecoveryOrderStatus.setText("待处理");
                                    tvDismissal.setVisibility(View.GONE);
                                    break;
                                case 2:
                                    tvRecoveryOrderStatus.setText("正在回收");
                                    tvDismissal.setVisibility(View.GONE);
                                    break;
                                case 3:
                                    tvRecoveryOrderStatus.setText("回收完毕");
                                    tvDismissal.setVisibility(View.GONE);
                                    break;
                                case 4:
                                    tvRecoveryOrderStatus.setText("申请失败");
                                    tvDismissal.setVisibility(View.VISIBLE);
                                    tvDismissal.setText("驳回理由:"+recoveryDetailEntity.getDismissal());
                                    break;
                            }


                            tvName.setText("收货人: " + recoveryDetailEntity.getName());
                            tvPhone.setText(recoveryDetailEntity.getPhone());
                            tvDetailAddress.setText("收货地址: " + recoveryDetailEntity.getAddress());

                            tvType.setText("物品分类: " + recoveryDetailEntity.getType());
                            tvGoodName.setText("物品名称: " + recoveryDetailEntity.getClassname());
                            tvTime.setText("预约时间: " + recoveryDetailEntity.getTime());
                            tvNote.setText("备       注: " + recoveryDetailEntity.getRemarks());
                            switch (type){
                                case "回收旧衣服":
                                    tvWeight.setText("重       量: "+recoveryDetailEntity.getWeight());
                                    tvQuality.setVisibility(View.GONE);
                                    viewLine.setVisibility(View.GONE);
                                    break;
                                case "回收电子产品":
                                    tvWeight.setText("产品信息: "+recoveryDetailEntity.getContent());
                                    tvQuality.setVisibility(View.GONE);
                                    viewLine.setVisibility(View.GONE);
                                    break;
                                case "回收书籍":
                                    tvWeight.setText("重       量: "+recoveryDetailEntity.getWeight());
                                    tvQuality.setText("成      色: "+recoveryDetailEntity.getQuality());
                                    break;
                                case "回收家具":
                                    tvWeight.setText("成      色: "+recoveryDetailEntity.getQuality());
                                    tvQuality.setVisibility(View.GONE);
                                    viewLine.setVisibility(View.GONE);
                                    break;
                                case "可回收垃圾":
                                    tvWeight.setText("重       量: "+recoveryDetailEntity.getWeight());
                                    tvQuality.setVisibility(View.GONE);
                                    viewLine.setVisibility(View.GONE);
                                    break;

                            }




                        } else {
                            MToast.makeTextShort(RecoveryOrderDetailActivity.this, msg).show();
                        }
                    }
                });
    }


}
